/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.mrp.atpm.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import merlion.mrp.ppm.entity.IndexNValue;
import merlion.scm.lcm.entity.DeliveryOrder;


/**
 *
 * @author Zhu Xin
 */
@Entity
public class PendingATP implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String pendingStrId;
    private String type; //indicates whether it is urgent RFQ or Sales Order
    
    @OneToOne(targetEntity = DeliveryOrder.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
    private DeliveryOrder deliveryOrder;
    
    private Timestamp requestedTime;
    
    public PendingATP() {
        
    }
    
    public PendingATP(String type, Timestamp requestedTime) {
        this.type = type;
        this.requestedTime = requestedTime;
        SimpleDateFormat sdf = new SimpleDateFormat("ssmmhhddMMyyyy");
        pendingStrId = type + sdf.format(requestedTime);
    }

    public String getPendingStrId() {
        return pendingStrId;
    }

    public void setPendingStrId(String pendingStrId) {
        this.pendingStrId = pendingStrId;
    }

    public DeliveryOrder getDeliveryOrder() {
        return deliveryOrder;
    }

    public void setDeliveryOrder(DeliveryOrder deliveryOrder) {
        this.deliveryOrder = deliveryOrder;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }


    public Timestamp getRequestedTime() {
        return requestedTime;
    }

    public void setRequestedTime(Timestamp requestedTime) {
        this.requestedTime = requestedTime;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PendingATP)) {
            return false;
        }
        PendingATP other = (PendingATP) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "merlion.mrp.atpm.entity.PendingATP[ id=" + id + " ]";
    }
    
}
